package com.example.myorder;

import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class Admin_OrderAdd extends AppCompatActivity {
    private List<String> data = new ArrayList<>();
    String data4;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.actitvity_orderadd);

        Resources resources = getResources();
        String[] str = resources.getStringArray(R.array.cai);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,data);
        for (String a:str){
            data.add(a);
        }
        Spinner spinner = findViewById(R.id.spinner2);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                data4 = data.get(position);
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }
    public void onAdd(View e){
        EditText e1 = findViewById(R.id.editText3);
        EditText e2 = findViewById(R.id.editText4);
        EditText e3 = findViewById(R.id.editText5);
        String data1 = e1.getText().toString();
        String data2 = e2.getText().toString();
        String data3 = e3.getText().toString();

        if(data1!=null) {
            if(data4!="请选择") {
                Intent intent = new Intent();
                intent.putExtra("data_returnName", data1);
                intent.putExtra("data_returnFlavor", data2);
                intent.putExtra("data_returnIngredients", data3);
                intent.putExtra("data_returnData", data4);
                setResult(RESULT_OK, intent);
                finish();
            }else {
                Toast.makeText(this,"请选择需要添加的饭馆！",Toast.LENGTH_SHORT).show();
            }
        }else{
            Toast.makeText(this,"请输入食品的菜名！",Toast.LENGTH_SHORT).show();
        }
    }
}
